From f6a72db8cff9ea990c3c1b81d91e2c6437ab18e8 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Fri, 18 Jan 2013 01:45:43 -0500 Subject: [PATCH] Preserve warnings on API error * In case of an error, any warnings generated by API modules before the error will be preserved in the result. * Spelling Change-Id: Ib61a1da90e9ce5df60ceccd0de8c6de9e49a22d6 --- RELEASE-NOTES-1.21 | 1 + includes/api/ApiMain.php | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/RELEASE-NOTES-1.21 b/RELEASE-NOTES-1.21 index 01ff993d55..a34cd17997 100644 --- a/RELEASE-NOTES-1.21 +++ b/RELEASE-NOTES-1.21 @@ -187,6 +187,7 @@ production. a redirect and its target. * (bug 43849) ApiQueryImageInfo no longer throws exceptions with ForeignDBRepo redirects. +* On error, any warnings generated before that error will be shown in the result. === API internal changes in 1.21 === * For debugging only, a new global $wgDebugAPI removes many API restrictions when true. diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 3f82d3c92d..70c31c1cce 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -384,7 +384,7 @@ class ApiMain extends ApiBase { } } - // Handle any kind of exception by outputing properly formatted error message. + // Handle any kind of exception by outputting properly formatted error message. // If this fails, an unhandled exception should be thrown so that global error // handler will process and log it. @@ -622,7 +622,6 @@ class ApiMain extends ApiBase { if ( $this->mPrinter->getWantsHelp() || $this->mAction == 'help' ) { ApiResult::setContent( $errMessage, $this->makeHelpMsg() ); } - } else { global $wgShowSQLErrors, $wgShowExceptionDetails; // Something is seriously wrong @@ -639,6 +638,10 @@ class ApiMain extends ApiBase { ApiResult::setContent( $errMessage, $wgShowExceptionDetails ? "\n\n{$e->getTraceAsString()}\n\n" : '' ); } + // Remember all the warnings to re-add them later + $oldResult = $result->getData(); + $warnings = isset( $oldResult['warnings'] ) ? $oldResult['warnings'] : null; + $result->reset(); $result->disableSizeCheck(); // Re-add the id @@ -646,11 +649,13 @@ class ApiMain extends ApiBase { if ( !is_null( $requestid ) ) { $result->addValue( null, 'requestid', $requestid ); } - if ( $wgShowHostnames ) { // servedby is especially useful when debugging errors $result->addValue( null, 'servedby', wfHostName() ); } + if ( $warnings !== null ) { + $result->addValue( null, 'warnings', $warnings ); + } $result->addValue( null, 'error', $errMessage ); -- 2.20.1